// 日志
const express = require('express');
const router = express.Router();
// 引入数据库
const db = require("../../config/db");

// 登录日志方法
const logLogin = (ClientIp,Name)=>{
    const date = new Date().getTime()
    const sql = "insert into log(`Date`, `ClientIp`, `Name`) values" + `(${date},'${ClientIp}','${Name}')`
    db.query(sql,function(){});
}

// 查询用户登录日志ip
router.post("/getClinetIpDate",(req,res)=>{
    const Name = req.body.Name
    if(Name){
        // 查询最大值筛选 const sql = "SELECT Name,max(Date) as Date ,ClientIp from log WHERE Name = " + `"${Name}" group by  ClientIp`
        const sql =  "SELECT  MAX(Date) Date ,  ClientIp ,`Name` FROM log WHERE Date<(SELECT MAX(Date) FROM log) && Name = " + `"${Name}" group by  ClientIp `
        db.query(sql,(err,results)=>{
            res.send({
                code:200,
                data:results,
            })
        })
    }else{
        res.send("用户为空")
    }
    
})

module.exports = {
    logLogin,
    logRouter:router
};